package com.car.controller;

import com.car.entity.Car;
import com.car.entity.VipCarBiling;
import com.car.service.impl.VipCarBilingServcie;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

@Controller
public class VipCarBilingConller {
    private SimpleDateFormat sdf= new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
    Date date = new Date();
    @Autowired
    @Qualifier("vipCarBilingServcie")
    private VipCarBilingServcie vipCarBilingServcie;

    //售后查询所有
    @RequestMapping(value = "shcx")
    public String Dealer(Model model){
        List<VipCarBiling> list = vipCarBilingServcie.after();
        model.addAttribute("sh",list);
        return "/afterSales_List.jsp";
    }

    //售后模糊查询
    @RequestMapping(value = "shmh")
    public String ThreeTableFuzzy(Model model,VipCarBiling vipCarBiling){
        if (vipCarBiling.getJieshu()==null||vipCarBiling.getJieshu()==""){
            vipCarBiling.setJieshu("9999-12-31");
            List<VipCarBiling> list1 = vipCarBilingServcie.fuzzySH(vipCarBiling);
            model.addAttribute("sh", list1);
        }else {
            List<VipCarBiling> list1 = vipCarBilingServcie.fuzzySH(vipCarBiling);
            System.out.println(list1);
            model.addAttribute("sh", list1);
        }
        return "/afterSales_List.jsp";
    }

    //售后的添加的查询
    @RequestMapping(value = "shtj")
    public String addTjcx(Model model){
        List<Car> list2 = vipCarBilingServcie.addfindAll();
        model.addAttribute("car",list2);
        return "/add_afterSales.jsp";
    }

    //售后的添加
    @RequestMapping(value = "stj",method = RequestMethod.POST)
    public String addtj(Model model,VipCarBiling vipCarBiling){
        vipCarBiling.setRegtime(sdf.format(date));
        vipCarBiling.setZhifu("微信");
        vipCarBilingServcie.addVipCarBiling(vipCarBiling);
        return "redirect:/add_afterSales.jsp";
    }

    //售后的模糊查询
    @RequestMapping(value = "shdcx")
    public String selectsh(Model model,Car car){
        List<Car> sss = vipCarBilingServcie.sch(car);
        model.addAttribute("car",sss);
        return "/add_afterSales.jsp";
    }
}
